import React from 'react'
import { useLocation, useParams } from 'react-router-dom'
import qs from 'qs'

export default function News() {

  const { search } = useLocation()
  const { username } = qs.parse(search.split('?')[1])

  const { id } = useParams()

  const newsList = useLocation().state

  return (
    <div>
      <h3>news</h3>
      <h5>id: {id} 用户: {username}</h5>
      {
        newsList.map(item => {
          return <p key={item.id}>{item.news}</p>
        })
      }
    </div>
  )
}
